import { ContentProjectionService, LocalizationParam } from '@abp/ng.core';
import { Confirmation, ConfirmationService } from '@abp/ng.theme.shared';
import { Observable, Subject } from 'rxjs';
import { NzModalService } from 'ng-zorro-antd/modal';
import { Injectable } from '@angular/core';
import { LocalizationService } from '@abp/ng.core';

@Injectable({ providedIn: 'root' })
export class NgConfirmationService extends ConfirmationService {
  constructor(
    contentProjectionService: ContentProjectionService,
    private modal: NzModalService,
    private localizationService: LocalizationService
  ) {
    super(contentProjectionService);
  }

  show(
    message: LocalizationParam,
    title: LocalizationParam,
    severity?: Confirmation.Severity,
    options = {} as Partial<Confirmation.Options>
  ): Observable<Confirmation.Status> {
    this.status$ = new Subject();
    this.modal[severity]({
      nzTitle: this.localizationService.instant(title),
      nzContent: this.localizationService.instant(message),
      nzOnOk: () => this.status$.next(),
    });

    return this.status$;
  }
}
